import json


def get_cookie(cookie_dict: dict):
    if cookie_dict is None:
        raise Exception("cookie 未找到")
    c = []
    for key in cookie_dict:
        c.append("{0}={1}".format(key, cookie_dict.get(key)))
    return ";".join(c)


def get_headers(content_type: str, host='22.230.57.12:8080'):
    return {
        "Host": host,
        "Accept": "*/*",
        'Content-Type': content_type,
        'Accept-Encoding': 'gzip, deflate, br',
        "User-Agent": "python-requests/2.25.1",
    }


def parse_response(res):
    if 'login' in res.request.path_url:
        raise Exception('403', 'session not found')
    try:
        return json.loads(res.content.decode('utf8'))
    except:
        return {}
